// Copyright (c) 2014 Morten Bakkedal
// This code is published under the MIT License.

using System;
using System.Collections.Generic;

using FuncLib.Functions;

namespace FuncLib.DualFunctions.Collections
{
	[Serializable]
	public sealed class HessianBuilder : Dictionary<HessianEntry, double>
	{
		public void Add(Variable variable1, Variable variable2, double value)
		{
			Add(new HessianEntry(variable1, variable2), value);
		}

		public bool Contains(Variable variable1, Variable variable2)
		{
			// Probably the fastest way to do this. This is O(1).
			return ContainsKey(new HessianEntry(variable1, variable2));
		}

		public Hessian ToHessian()
		{
			return new Hessian(this);
		}

		public double this[Variable variable1, Variable variable2]
		{
			get
			{
				return this[new HessianEntry(variable1, variable2)];
			}
			set
			{
				this[new HessianEntry(variable1, variable2)] = value;
			}
		}
	}
}
